<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('after_sales_approvals', function (Blueprint $table) {
            $table->id();
            $table->foreignId('request_id')->constrained('after_sales_requests')->onDelete('cascade')->comment('售后申请ID');
            $table->foreignId('admin_id')->constrained('users')->onDelete('cascade')->comment('管理员ID');
            
            // 审批信息
            $table->enum('action', ['approve', 'reject', 'process', 'complete', 'cancel'])
                ->comment('操作：approve-通过，reject-拒绝，process-开始处理，complete-完成，cancel-取消');
            $table->text('reason')->nullable()->comment('操作原因');
            $table->text('comment')->nullable()->comment('备注');
            
            // 金额调整（仅退款时）
            $table->decimal('amount_adjustment', 10, 2)->default(0)->comment('金额调整');
            
            $table->timestamps();
            
            // 索引
            $table->index(['request_id', 'action']);
            $table->index('admin_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('after_sales_approvals');
    }
};
